package top.dancun.easbaseinfo.controller;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.dancun.common.utils.R;
import top.dancun.easbaseinfo.entity.DeptEntity;
import top.dancun.easbaseinfo.service.DeptService;

import java.util.Arrays;
import java.util.List;
import java.util.Map;



/**
 * 
 *
 * @author dancun
 * @email message@dancun.top
 * @date 2022-09-17 16:31:58
 */
@RestController
@RequestMapping("/dept")
public class DeptController extends AbstractController{
    @Autowired
    private DeptService deptService;

    /**
     * 列表
     */
    @RequestMapping("/list")
    @RequiresPermissions("easbaseinfo:dept:list")
    public R list(@RequestBody Map<String, Object> params){
        List<DeptEntity> depts = deptService.listDeptTree();

        return R.ok().put("data", depts);
    }


    /**
     * 信息
     */
    @RequestMapping("/info/{deptId}")
    @RequiresPermissions("easbaseinfo:dept:info")
    public R info(@PathVariable("deptId") Integer deptId){
		DeptEntity dept = deptService.getById(deptId);

        return R.ok().put("dept", dept);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")
    @RequiresPermissions("easbaseinfo:dept:save")
    public R save(@RequestBody DeptEntity dept){
		deptService.save(dept);

        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    @RequiresPermissions("easbaseinfo:dept:update")
    public R update(@RequestBody DeptEntity dept){
		deptService.updateById(dept);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    @RequiresPermissions("easbaseinfo:dept:delete")
    public R delete(@RequestBody Integer[] deptIds){
		deptService.removeByIds(Arrays.asList(deptIds));

        return R.ok();
    }

}
